package shared

import (
	"crypto/sha256"
	"encoding/base64"
	"strconv"
	"time"
)

// These are part of private members from Go's time package. It can tell you what happens to our date format constants.
//
//const (
//	stdLongMonth             = iota + stdNeedDate  // "January"
//	stdMonth                                       // "Jan"
//	stdNumMonth                                    // "1"
//	stdZeroMonth                                   // "01"
//	stdLongWeekDay                                 // "Monday"
//	stdWeekDay                                     // "Mon"
//	stdDay                                         // "2"
//	stdUnderDay                                    // "_2"
//	stdZeroDay                                     // "02"
//	stdUnderYearDay                                // "__2"
//	stdZeroYearDay                                 // "002"
//	stdHour                  = iota + stdNeedClock // "15"
//	stdHour12                                      // "3"
//	stdZeroHour12                                  // "03"
//	stdMinute                                      // "4"
//	stdZeroMinute                                  // "04"
//	stdSecond                                      // "5"
//	stdZeroSecond                                  // "05"
//	stdLongYear              = iota + stdNeedDate  // "2006"
//	stdYear                                        // "06"
//)
//
// That's why these date format constants look strange.
const (
	LongDateFormat     = "2006-01-02"          // Treats it as yyyy-MM-dd
	LongDateTimeFormat = "2006-01-02 15:04:05" // Treats it as yyyy-MM-dd HH:mm:ss
)

// H is a shortcut for map[string]interface{}
type MapData map[string]interface{}

// Gets current system date time.
func GetCurrentTime() time.Time {
	return time.Now()
}

// Converts the input string to int type.
func StringToInt(str string) (int, error) {
	return strconv.Atoi(str)
}

// Converts the input int value to string type.
func IntToString(value int) string {
	return strconv.Itoa(value)
}

// Encrypts input string without key.
// Normally it used to encrypt password before saving.
func EncryptWithoutKey(content string) string {
	bytes := sha256.Sum256([]byte(content))
	return base64.StdEncoding.EncodeToString(bytes[:])
}
